package com.joolun.web.controller.activity;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.activity.domain.ActivityInfo;
import com.joolun.activity.service.IActivityInfoService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 活动Controller
 *
 * @author www.joolun.com
 * @date 2022-11-22
 */
@RestController
@RequestMapping("/activity/activityInfo")
public class ActivityInfoController extends BaseController
{
    @Autowired
    private IActivityInfoService activityInfoService;

    /**
     * 查询活动列表
     */
    @PreAuthorize("@ss.hasPermi('activity:activityInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityInfo activityInfo)
    {
        startPage();
        List<ActivityInfo> list = activityInfoService.selectActivityInfoList(activityInfo);
        return getDataTable(list);
    }

    /**
     * 导出活动列表
     */
    @PreAuthorize("@ss.hasPermi('activity:activityInfo:export')")
    @Log(title = "活动", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ActivityInfo activityInfo)
    {
        List<ActivityInfo> list = activityInfoService.selectActivityInfoList(activityInfo);
        ExcelUtil<ActivityInfo> util = new ExcelUtil<ActivityInfo>(ActivityInfo.class);
        return util.exportExcel(list, "activityInfo");
    }

    /**
     * 获取活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:activityInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(activityInfoService.selectActivityInfoById(id));
    }

    /**
     * 新增活动
     */
    @PreAuthorize("@ss.hasPermi('activity:activityInfo:add')")
    @Log(title = "活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityInfo activityInfo)
    {
        return toAjax(activityInfoService.insertActivityInfo(activityInfo));
    }

    /**
     * 修改活动
     */
    @PreAuthorize("@ss.hasPermi('activity:activityInfo:edit')")
    @Log(title = "活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityInfo activityInfo)
    {
        return toAjax(activityInfoService.updateActivityInfo(activityInfo));
    }

    /**
     * 删除活动
     */
    @PreAuthorize("@ss.hasPermi('activity:activityInfo:remove')")
    @Log(title = "活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(activityInfoService.deleteActivityInfoByIds(ids));
    }
    /**
     * 标记活动奖品
     */
    @PreAuthorize("@ss.hasPermi('activity:activityInfo:remove')")
    @Log(title = "标记活动奖品", businessType = BusinessType.DELETE)
    @DeleteMapping("/award/{ids}")
    public AjaxResult removeAward(@PathVariable String[] ids)
    {
        return toAjax(activityInfoService.removeAward(ids));
    }

    /**
     * 初始化活动参与码
     */
    @PreAuthorize("@ss.hasPermi('activity:activityInfo:remove')")
    @Log(title = "初始化活动参与码", businessType = BusinessType.DELETE)
    @DeleteMapping("/init/{ids}")
    public AjaxResult initTakeInfo(@PathVariable String[] ids)
    {
        return toAjax(activityInfoService.initTakeInfo(ids));
    }
}
